#include "pagestatistic.h"

staticPage::staticPage(QWidget *parent)
    : QWidget(parent)
{
    setFixedSize(1000,300);

    setStyleSheet("border:1px solid gray;");

    setStyleSheet(".QLabel{color:gray; font-size:14px;border:1px solid gray;min-height:35px;}"
                  ".QCheckBox{color:gold; font-size:14px; spacing:10px;}");

    btnSave = new QPushButton("保存");
    btnSave->setFixedSize(100,40);

    QCheckBox *checkAutoSave = new QCheckBox("自动保存");
    checkAutoSave->setFixedSize(100,25);
    checkAutoSave->setChecked(false);

    QLabel *labStatisticalTimes = new QLabel("统计次数");
    labStatisticalTimes->setStyleSheet("border:0px;");
    labStatisticalTimes->setFixedSize(100,25);
    inputStatisticalTimes = new QLineEdit("5");
    inputStatisticalTimes->setFixedSize(100,30);

    QVBoxLayout *layoutFunc = new QVBoxLayout;
    layoutFunc->addSpacing(20);
    layoutFunc->addWidget(btnSave);
    layoutFunc->addSpacing(30);
    layoutFunc->addWidget(checkAutoSave);
    layoutFunc->addWidget(labStatisticalTimes);
    layoutFunc->addWidget(inputStatisticalTimes);
    layoutFunc->addStretch(1);

    QLabel *labAvg_N = new QLabel("有效值误差");
    labAvg_N->setStyleSheet("background-color:turquoise;color:blue");

    QLabel *labPhaseAvg_N = new QLabel("相位误差");
    labPhaseAvg_N->setStyleSheet("background-color:turquoise;color:blue");

    QString sty_data="color: white; font-weight:bold;";

    QGridLayout *layoutData = new QGridLayout;
    layoutData->setSpacing(0);
    layoutData->addWidget(labAvg_N, 0, 1, 1, 3);
    layoutData->addWidget(labPhaseAvg_N, 0, 4, 1, 3);
    layoutData->addWidget((new QLabel("Ua")), 2, 0, 1, 1);
    layoutData->addWidget((new QLabel("Ub")), 3, 0, 1, 1);
    layoutData->addWidget((new QLabel("Uc")), 4, 0, 1, 1);
    layoutData->addWidget((new QLabel("Ia")), 5, 0, 1, 1);
    layoutData->addWidget((new QLabel("Ib")), 6, 0, 1, 1);
    layoutData->addWidget((new QLabel("Ic")), 7, 0, 1, 1);

    layoutData->addWidget((new QLabel("平均误差")), 1, 1, 1, 1);
    layoutData->addWidget((new QLabel("最大误差")), 1, 2, 1, 1);
    layoutData->addWidget((new QLabel("均方误差")), 1, 3, 1, 1);

    layoutData->addWidget((new QLabel("平均误差")), 1, 4, 1, 1);
    layoutData->addWidget((new QLabel("最大误差")), 1, 5, 1, 1);
    layoutData->addWidget((new QLabel("均方误差")), 1, 6, 1, 1);

    for(int ind=0; ind<6; ind++)
    {
        r_avg[ind] = new QLabel("0.0000");
        r_avg[ind]->setStyleSheet(sty_data);
        p_avg[ind] = new QLabel("0.0000");
        p_avg[ind]->setStyleSheet(sty_data);

        r_rms[ind] = new QLabel("0.0000");
        r_rms[ind]->setStyleSheet(sty_data);
        p_rms[ind] = new QLabel("0.0000");
        p_rms[ind]->setStyleSheet(sty_data);

        r_max[ind] = new QLabel("0.0000");
        r_max[ind]->setStyleSheet(sty_data);
        p_max[ind] = new QLabel("0.0000");
        p_max[ind]->setStyleSheet(sty_data);

        layoutData->addWidget(r_avg[ind], ind+2, 1, 1, 1);
        layoutData->addWidget(r_rms[ind], ind+2, 3, 1, 1);
        layoutData->addWidget(r_max[ind], ind+2, 2, 1, 1);
        layoutData->addWidget(p_avg[ind], ind+2, 4, 1, 1);
        layoutData->addWidget(p_rms[ind], ind+2, 6, 1, 1);
        layoutData->addWidget(p_max[ind], ind+2, 5, 1, 1);
    }

    layoutData->setRowStretch(7,1);

//    QLabel *labBlank = new QLabel("");
//    labBlank->setStyleSheet(".QLabel{background-color:gray;}");
//    labBlank->setFixedSize(2,300);

    QHBoxLayout *layoutMain = new QHBoxLayout;
    layoutMain->addLayout(layoutData);
//    layoutMain->addWidget(labBlank);
    layoutMain->addSpacing(15);
    layoutMain->addLayout(layoutFunc);

    setLayout(layoutMain);
}
